package com.guchenbo.demo.jdbc.service;

import com.guchenbo.demo.jdbc.dao.pojo.User1;
import com.guchenbo.demo.jdbc.dao.pojo.User2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用来测试不同事务传播行为
 *
 * @Author guchenbo
 * @Date 2020/3/24.
 */
@Service
public class TestManagerImpl implements TestManager {

    @Autowired
    private User1Service user1Service;
    @Autowired
    private User2Service user2Service;

    @Override
    public void m1() {
        User1 user1 = new User1();
        user1.setName("tom");
        user1Service.addRequired(user1);

        User2 user2 = new User2();
        user2.setName("jerry");
        user2Service.addRequired(user2);
    }

    /**
     *
     */
    @Override
    @Transactional
    public void m2() {
        User1 user1 = new User1();
        user1.setName("tom");

        user1Service.addRequiredException(user1);
        user1.setName("tom_new");

        user1Service.addRequiredNew(user1);

    }

    @Override
    @Transactional
    public void m3() {
        User1 user1 = new User1();
        user1.setName("tom");

        user1Service.addNested(user1);
        user1.setName("tom2");

        user1Service.addNestedException(user1);

    }
}
